from ..logger import log
from .capmonster import Proxy


class TurnstileTask(Proxy):
    def __init__(self, client_key):
        super(TurnstileTask, self).__init__(client_key)

    async def create_task(
        self, website_url: str, website_key: str, no_cache: bool = None
    ) -> int:
        data = {
            "clientKey": self._client_key,
            "task": {
                "type": "TurnstileTask",
                "websiteURL": website_url,
                "websiteKey": website_key,
            },
        }
        data, is_proxy = await self._is_proxy_task(data)
        if no_cache:
            data["task"]["nocache"] = no_cache
        response = await self._make_request("createTask", data)
        return response.get("taskId")
